/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webcarrito.ejb;

import com.webcarrito.entidades.Cliente;
import com.webcarrito.factory.Conexion;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author root
 */
@Stateless
public class SessionBeanSecurity implements SessionBeanSecurityRemote, SessionBeanSecurityLocal {

    private Conexion conexion = new Conexion("root", "root");
    private Statement statement = null;
    private ResultSet resultset = null;

    public String ValidaCliente(String usuario, String password) {
        Cliente c = new Cliente();
        try {


            resultset = getResultsetGenerico("select * from webcarritoejb.CLIENTE");
            while (resultset.next()) {
                return "valido";
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "invalido";
    }

    public Conexion getConexion() {
        return conexion;
    }

    public void setConexion(Conexion conexion) {
        this.conexion = conexion;
    }

    public ResultSet getResultsetGenerico(String comando) {
        Connection mc = conexion.get();
        ResultSet r = null;
        try {
            statement = mc.createStatement();
            r = statement.executeQuery(comando);
        } catch (Exception e) {
            e.printStackTrace();
            r = null;
        } finally {
            if (mc != null) {
                try {
                    mc.close();
                } catch (SQLException ex) {
                    Logger.getLogger(SessionBeanCarrito.class.getName()).log(Level.SEVERE, null, ex);
                }
                mc = null;
                statement = null;
            }
        }
        return r;
    }
}
